<?php

if($_POST['act'] == 'act'){
	$param = $_POST;
	foreach($param['model_name'] as $key => $val){
		$param['statu'][$key] = $_POST['statu'][$key] ? $_POST['statu'][$key] : 0 ;
		$time = time();
		if(empty($param['ids'][$key])){
			$sql = "insert into ".SPOTMODEL." (`spot_id`,`model_name`,`statu`,`displayorders`,`add_at`,`price`) values (
			'{$param['spot_id_up']}','$val','{$param['statu'][$key]}','{$param['displayorders'][$key]}','$time','{$param['price'][$key]}')";
			$db->query($sql);

		} else {

			$sql = "update ".SPOTMODEL." set model_name = '$val',statu='{$param['statu'][$key]}', displayorders = '{$param['displayorders'][$key]}', price = '{$param['price'][$key]}' where id = '{$param['ids'][$key]}' ";
			$db->query($sql);

		}

		if(!empty($param['delete_id'][$key])){
			$sql = "delete from ".SPOTMODEL." where id = '{$param['delete_id'][$key]}' ";
				$db->query($sql);
		}

	}

	echo "<script>window.parent.main.document.location.reload();window.parent.DialogManager.close('spot_model');</script>";
	msg("?m=spot&s=spot.php");

}else {
	$spot_id = $_GET['spot_id'] ? $_GET['spot_id'] : 0;
	$sql="select * from ".SPOTMODEL." where spot_id ='$spot_id' ";
	$db->query($sql);
	$spot_model = $db->getRows();


}
$tpl->assign("list",$spot_model);
	$tpl->assign("spot_id",$spot_id);
$tpl->assign("config",$config);
$tpl->assign("lang",$lang);
$tpl->display("model_spot.htm");
?>